package Controllers;

import Bean.BeanTeacher;
import Impl.TeacherServiceImpl;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@Controller
public class TeacherAddController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    TeacherServiceImpl teacherService;
	 @RequestMapping(value = "/TeacherAdd", method = RequestMethod.POST)
		@ResponseBody
		public JSONObject userRegister(HttpServletRequest request,@RequestBody JSONObject in) throws Exception {
		 	ApplicationContext applicationContext=(ApplicationContext)request.getSession().getServletContext().getAttribute("ctx");
	        teacherService=(TeacherServiceImpl) applicationContext.getBean("TeacherServiceImpl");
			JSONObject obj = new JSONObject();
			BeanTeacher teacher = new BeanTeacher();
			teacher.setTeacher_id(in.getString("teacherid"));
			teacher.setTeacher_name(in.getString("teachername"));
			teacher.setTeacher_photo(in.getString("teacherphoto"));
			teacher.setTeacher_introduction(in.getString("teacherintroduction"));
			teacherService.teacheradd(teacher.getTeacher_id(), in.getString("pwd"),teacher.getTeacher_name(), teacher.getTeacher_photo(), teacher.getTeacher_introduction());
			obj.put("status", "OK");
			return obj;
		}
}
